<!-- 添加角色 -->
<form id="roleForm" lay-filter="roleForm" class="layui-form" style="height: 100%; margin: 0 10px;">
    <div style="padding: 5px;"></div>
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label" style="white-space: nowrap; text-align: left;">角色标识：</label>
        <div class="layui-input-block" style="margin-left: 15px;">
            <input name="roleCode" id="roleCode" placeholder="请输入角色标识，必填" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="white-space: nowrap; text-align: left;">角色名称：</label>
        <div class="layui-input-block" style="margin-left: 15px;">
            <input name="roleName" id="roleName" placeholder="请输入角色名称，必填" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="white-space: nowrap; text-align: left;">是否默认角色</label>
        <div class="layui-input-block" style="margin-left: 15px;">
          <input type="checkbox" name="isDefault" id="isDefault" value="1" lay-text="是|否" lay-skin="switch">
        </div>
      </div> 
    <div class="layui-btn-container model-form-footer">
        <button class="layui-btn layui-btn-sm" id="item-form-submit" lay-filter="roleFormSubmit" lay-submit>提交</button>
    </div>
</form>

<script>
    layui.use(['layer', 'base', 'form'], function () {
        var $ = layui.jquery,
        layer = layui.layer,
        base = layui.base,
        form = layui.form;

        base.fsAjax('/baseService/role/initForm', {}, function (data) {
            layer.closeAll('loading');
            if (data.code == 200) {
                data = data.data;
                form.val('roleForm', data);
                form.render();
            } else {
                base.msgError(data.msg);
            }
        },  "POST"); 
 		
        // 表单提交事件
        form.on('submit(roleFormSubmit)', function (data) {
            debugger
            var url = '/baseService/role/editRole';
            if( data.field.id === ''){
                url = '/baseService/role/addRole'; 
            }
            base.fsAjax(url, JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    base.msgSuccess(data.msg);
                    base.close();
                } else {
                    base.msgError(data.msg);
                }
            },  "POST");
            return false;
        });
    });
</script>